package org.example;

import org.apache.hadoop.io.Writable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

public class ResultXinguan implements Writable {
    private NumberInfo numberInfo;
    private double Mortality; //死亡率（死亡/确诊）
    private double RecoveryRate;//康复率（康复/确诊）
    private Long ActiveCases; //活跃病例（确诊-死亡-康复）
    private Long Confirmed; //已确诊，累计
    private Long Deaths; //死亡，累计
    private Long Health; //恢复，累计
    private String Province; //省份



    public ResultXinguan() {
    }

    public ResultXinguan(NumberInfo numberInfo) {
        this.numberInfo = numberInfo;
        Confirmed = this.numberInfo.getConfirmed();
        Deaths = this.numberInfo.getDeaths();
        Health = this.numberInfo.getHealth();
        Province = this.numberInfo.getProvince();
        ActiveCases = Confirmed-Deaths-Health;

        if (Confirmed != 0) {
            Mortality = (double)Deaths / Confirmed;
            RecoveryRate = (double)Health / Confirmed;
        } else {
            Mortality = 0.0;
            RecoveryRate = 0.0;
        }
    }


    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeDouble(Mortality);
        dataOutput.writeDouble(RecoveryRate);
        dataOutput.writeLong(ActiveCases);
        dataOutput.writeLong(Confirmed);
        dataOutput.writeLong(Deaths);
        dataOutput.writeLong(Health);
        dataOutput.writeUTF(Province);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        Mortality = dataInput.readDouble();
        RecoveryRate = dataInput.readDouble();
        ActiveCases = dataInput.readLong();
        Confirmed = dataInput.readLong();
        Deaths = dataInput.readLong();
        Health = dataInput.readLong();
        Province = dataInput.readUTF();
    }

    @Override
    public String toString() {
        return Mortality + "\t" + RecoveryRate + "\t" + ActiveCases + "\t" + Confirmed + "\t" + Deaths + "\t" + Health + "\t" + Province;
    }

    public NumberInfo getNumberInfo() {
        return numberInfo;
    }

    public void setNumberInfo(NumberInfo numberInfo) {
        this.numberInfo = numberInfo;
    }

    public double getMortality() {
        return Mortality;
    }

    public void setMortality(double mortality) {
        Mortality = mortality;
    }

    public double getRecoveryRate() {
        return RecoveryRate;
    }

    public void setRecoveryRate(double recoveryRate) {
        RecoveryRate = recoveryRate;
    }

    public Long getActiveCases() {
        return ActiveCases;
    }

    public void setActiveCases(Long activeCases) {
        ActiveCases = activeCases;
    }

    public Long getConfirmed() {
        return Confirmed;
    }

    public void setConfirmed(Long confirmed) {
        Confirmed = confirmed;
    }

    public Long getDeaths() {
        return Deaths;
    }

    public void setDeaths(Long deaths) {
        Deaths = deaths;
    }

    public Long getHealth() {
        return Health;
    }

    public void setHealth(Long health) {
        Health = health;
    }

    public String getProvince() {
        return Province;
    }

    public void setProvince(String province) {
        Province = province;
    }
}
